yjx.controller('productPlanController', ['$rootScope', '$scope', '$stateParams', '$timeout', '$fetch', 'modalService', '$init', function ($rootScope, $scope, $stateParams, $timeout, $fetch, $modalService, $init) {
    var forwardId = $stateParams.forwardId;
    var customerId = $stateParams.customerId;
    var productIds = $stateParams.productIds;
    var tabApi = '/customer/navigation/data';
    $scope.discountPrice = $stateParams.discountPrice;
    $scope.producRectList = [];
    $scope.totalPrice = 0;
    $init.title("产品计划书")
    if (forwardId && customerId) {
            $timeout(function () {
                getProductPlan();
            })
    }
    if (productIds) {
        var productIdsArr = productIds.split(',');
        for (var i = 0; i < productIdsArr.length; i++) {
            getProduct(productIdsArr[i]);
        }
    }
    /**产品计划书 */
    function getProductPlan() {
        $fetch.fetch(
            tabApi,
            {
                params: {
                    userId: forwardId,
                    customerId: customerId,
                    dataType: 'j'
                },
                cache: false
            }
        ).then(function (data) {
            $timeout(function () {
                $scope.plan = data;
            })
        }).catch(function (e) {
            modalService.mainMsgError(e.msg);
        })
    }
    /**获取产品基础信息 */
    function getProduct(id) {
        $fetch.fetch(
            '/product/getSimpleDetail',
            {
                params: { productId: id }
            }
        ).then(function (data) {
            $scope.producRectList.push(data);
            var price = data.price ? data.price : data.originalPrice;
            $scope.totalPrice = $scope.totalPrice + price;
        })
    }

}])